<template>
  <div>
    <span v-for="(v, i) in arr" :key="i">
      <input type="checkbox" @change="btn(i, v, $event)" />{{ v }}
    </span>
    <ul>
      <li v-for="(v, i) in newarr" :key="i">{{ v }}</li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: ["科幻", "喜剧", "动漫", "冒险", "科技", "军事", "娱乐", "奇闻"],
      newarr: [],
      choose: false,
    };
  },
  methods: {
    btn(index, v, e) {
      console.log(e.target.checked);
      if (e.target.checked) {
        this.newarr.push(this.arr[index]);
        console.log(this.newarr);
      } else {
        Array.prototype.indexOf = function (val) {
          for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
          }
          return -1;
        };
        Array.prototype.remove = function (val) {
          var index = this.indexOf(val);
          if (index > -1) {
            this.splice(index, 1);
          }
        };
        this.newarr.remove(v);
      }
    },
  },
};
</script>

<style scoped>
</style>
